<template>
  <div class="login-container">
    <div class="login-content">
    <el-header class="header-text">
      <el-text class="bigdata-docker-management-service" size="100" style="font-size: 36px;">
        BigData Docker Mangement Service
      </el-text>
    </el-header>
    <div class="flex flex-col justify-center items-center shadow-dark" m="auto" w="46">
      <div class="inline-flex shadow-box" h="60" w="60" m="20">
        <div class="login-form">
          <div>
            <!-- <label for="username">用户名:</label> -->
            <label for="username">
              <el-text class="mx-1" size="large">UserName: </el-text>
            </label>
            <!-- <input id="username" v-model="username" type="text" placeholder="请输入用户名" /> -->
            <el-input v-model="username" type="text" style="width: 240px" placeholder="Please input UserName" />
          </div>
          <div>
            <!-- <label for="password">密码:</label> -->
            <label for="password">
              <el-text class="mx-1" size="large">Password: </el-text>
            </label>
            <!-- <input id="password" v-model="password" type="password" placeholder="请输入密码" /> -->
            <el-input v-model="password" type="password" style="width: 240px" placeholder="Please input Password" />
          </div>
          <!-- <button @click="login">登录</button> -->
          <el-button type="primary" @click="login">
            <!-- 登录 -->
            <el-text class="mx-1" size="large" style="color: white">Login</el-text>
          </el-button>
        </div>
      </div>
    </div>
  </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router'; // 导入useRouter

// 使用ref声明状态变量
const username = ref('');
const password = ref('');
const router = useRouter(); // 创建路由实例

const login = async () => {
  try {
    const response = await axios.post('http://localhost:8080/docker-management/auth/login', {
      username: username.value,
      password: password.value,
    });

    if (response.data.code === 200) {
      if (response.data.data == true) {
        // alert('登录成功');
        router.push('/App'); // 导航到首页页面
      } else {
        alert('登录失败，账号密码有误');
      }
    } else {
      alert('登录失败，无法获取到用户信息');
    }
  } catch (error) {
    console.error('请求失败', error);
    alert('登录失败，请求后端接口失败');
  }
};

const shadowGroup = [
  {
    name: 'Dark Shadow',
    type: 'dark',
  },
];

const getCssVarName = function (type) {
  return `--el-box-shadow${type ? '-' : ''}${type}`;
};


</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.login-content {
  display: flex;
  flex-direction: column; /* 垂直排列标题和表单 */
  justify-content: center;
  align-items: center;
  text-align: center; /* 使文字居中 */
}

.header-text {
  margin-bottom: 20px; /* 标题与表单之间的间距 */
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 20px; /* 增加输入框和按钮之间的间距 */
  padding: 20px; /* 增加内边距 */
  background-color: #fff; /* 添加背景色以便更好地显示内边距效果 */
  border-radius: 8px; /* 可选：添加圆角 */
}

.shadow-dark {
  --el-box-shadow-dark: 0 10px 20px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.15);
  box-shadow: var(--el-box-shadow-dark);
  padding: 20px; /* 增加内边距 */
  border-radius: 8px; /* 可选：添加圆角边框 */
  background-color: #fff; /* 添加背景色以便更好地显示阴影效果 */
}
</style>


